//
//  CalenderPicker.m
//  SportRing
//
//  Created by 微我网络 on 15/1/23.
//  Copyright (c) 2015年 HotOne. All rights reserved.
//

#import "CalendarPicker.h"

const int buttonWidth = 30;

@interface CalendarPicker ()

@property (nonatomic) NSDate *now;
@property (nonatomic) NSCalendar *calendar;
@property (nonatomic) NSDateComponents *comp;

@end

@implementation CalendarPicker

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        
        _now = [NSDate date];
        _calendar = [NSCalendar currentCalendar];
        _comp = [[NSCalendar currentCalendar] components:NSYearCalendarUnit|NSMonthCalendarUnit|NSDayCalendarUnit|NSWeekdayCalendarUnit
                                                fromDate:[NSDate date]];
        
        self.backgroundColor = [UIColor clearColor];
        
        _previous = [UIButton buttonWithType:UIButtonTypeCustom];
        _previous.frame = CGRectMake(0, 0, buttonWidth, frame.size.height);
//        _previous.backgroundColor = [UIColor redColor];
        [_previous setImage:[UIImage imageNamed:@"leftArrow"] forState:UIControlStateNormal];
        [_previous setImageEdgeInsets:UIEdgeInsetsMake(8, 0, 8, 17)];
        [self addSubview:_previous];
        
        _next = [UIButton buttonWithType:UIButtonTypeCustom];
        _next.frame = CGRectMake(frame.size.width-buttonWidth, 0, buttonWidth, frame.size.height);
//        _next.backgroundColor = [UIColor greenColor];
        [_next setImage:[UIImage imageNamed:@"rightArrow"] forState:UIControlStateNormal];
        [_next setImageEdgeInsets:UIEdgeInsetsMake(8, 17, 8, 0)];
        [self addSubview:_next];
        
        _dateLabel = [[UILabel alloc] initWithFrame:CGRectMake(buttonWidth, 0, frame.size.width-buttonWidth*2, frame.size.height)];
        _dateLabel.textAlignment = NSTextAlignmentCenter;
        _dateLabel.textColor = [UIColor colorWithWhite:1 alpha:0.4];
//        _dateLabel.backgroundColor = [UIColor orangeColor];
        [self addSubview:_dateLabel];
        
//        [self setMode:0];
    }
    return self;
}

- (void)setMode:(CalendarPickerMode)mode {
    
    _mode = mode;
    switch (mode) {
            
        case 0:
            _dateLabel.text = [NSString stringWithFormat:@"%ld-%ld",_comp.year,_comp.month];
            break;
            
        case 1:
            _dateLabel.text = [NSString stringWithFormat:@"%ld-%ld",_comp.year,_comp.month];
            break;
            
        case 2:
            _dateLabel.text = [NSString stringWithFormat:@"%ld-%ld",_comp.year,_comp.month];
            break;
            
        default:                 
            break;
    }
}


/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
